#
# @lc app=leetcode.cn id=2905 lang=python3
#
# [2905] 找出满足差值条件的下标 II
#

# @lc code=start
from typing import List
# nums[i] - nums[j] >= value
# nums[i] - nums[j] >= valueDifference || nums[]

class Solution:
    def findIndices(self, nums: List[int], indexDifference: int, valueDifference: int) -> List[int]:
        #  j - i >= indexDifference  == i <= j - indexDifference
        #   维护[0 , j - indexDifference] 最小值和最大值的下标
        max_id = min_id = 0
        n = len(nums)
        i = 0
        # j 直接从 indexDifference 开始  有点定长和滑动窗口的意思 
        for j in range(indexDifference,n):
            if nums[i] > nums[max_id] :
                max_id = i
            elif nums[i] < nums[min_id]:
                min_id = i

            if nums[max_id] - nums[j] >= valueDifference:
                return [max_id,j]
            if nums[j] - nums[min_id] >= valueDifference:
                return [min_id,j]
            i += 1
        return [-1,-1]

        
# @lc code=end

